
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Apps.Models;
using Apps.Common;
using Microsoft.Practices.Unity;
using System.Transactions;
using Apps.BLL.Core;
using Apps.Locale;
using LinqToExcel;
using System.IO;
using System.Text;
using System.Linq.Expressions;
using Apps.IDAL.PUB;
using Apps.Models.PUB;
using Apps.IBLL.PUB;
using System.Text.RegularExpressions;

namespace Apps.BLL.PUB
{
	public partial class PUB_CAR_OPERATEBLL: Virtual_PUB_CAR_OPERATEBLL,IPUB_CAR_OPERATEBLL
	{
        public List<PUB_CAR_OPERATEModel> GetLists(ref GridPager pager, string queryStr)
        {
            try
            {

                using (DBContainer db = new DBContainer())
                {
                    #region EF操作拼接数据
                    /*
                    var caroper = (from c in db.PUB_CAR_OPERATE
                                   join b in db.SysUser
                                         on c.REGISTER_USER_ID equals b.Id into RUSER
                                   from bb in RUSER.DefaultIfEmpty()
                                   join a in db.SysUser
                                         on c.UPDATE_USER_ID equals a.Id into UUSER
                                   from aa in UUSER.DefaultIfEmpty()
                                   join d in db.SysUser
                                         on c.UNREGISTER_USER_ID equals d.Id into UNUSER
                                   from dd in UNUSER.DefaultIfEmpty()
                                   select new PUB_CAR_OPERATEModel
                                   {
                                       CAR_ID = c.CAR_ID,
                                       RFID = c.RFID,
                                       LPR = c.LPR,
                                       DRIVER_IDCARD = c.DRIVER_IDCARD,
                                       DRIVER_PHONE = c.DRIVER_PHONE,
                                       SPECIFIED_WEIGHT = c.SPECIFIED_WEIGHT,
                                       TARE = c.TARE,
                                       TOTLE_LENGTH = c.TOTLE_LENGTH,
                                       TOTLE_WIDTH = c.TOTLE_WIDTH,
                                       LENGTH = c.LENGTH,
                                       WIDTH = c.WIDTH,
                                       HEIGHT = c.HEIGHT,
                                       POSTIONS = c.POSTIONS,
                                       REGISTER_USER_ID = bb.TrueName,
                                       REGISTER_TIME = c.REGISTER_TIME,
                                       UPDATE_USER_ID = aa.TrueName,
                                       UPDATE_TIME = c.UPDATE_TIME,
                                       STATUS = c.STATUS == true ? 1 : 0,
                                       UNREGISTER_TIME = c.UNREGISTER_TIME,
                                       UNREGISTER_REASON = c.UNREGISTER_REASON,
                                       DRIVER_NAME = c.DRIVER_NAME,
                                       UNREGISTER_USER_ID = dd.TrueName,
                                       CAR_TYPE = c.CAR_TYPE,
                                       CAR_SIZE = c.CAR_SIZE
                                   }).OrderBy(o => o.UPDATE_TIME).Take(10).AsEnumerable().Select((cc, index) => new PUB_CAR_OPERATEModel
                                   {
                                       CAR_ID = "第" + (index + 1) + "次操作",
                                       RFID = cc.RFID,
                                       LPR = cc.LPR,
                                       DRIVER_IDCARD = cc.DRIVER_IDCARD,
                                       DRIVER_PHONE = cc.DRIVER_PHONE,
                                       SPECIFIED_WEIGHT = cc.SPECIFIED_WEIGHT,
                                       TARE = cc.TARE,
                                       TOTLE_LENGTH = cc.TOTLE_LENGTH,
                                       TOTLE_WIDTH = cc.TOTLE_WIDTH,
                                       LENGTH = cc.LENGTH,
                                       WIDTH = cc.WIDTH,
                                       HEIGHT = cc.HEIGHT,
                                       POSTIONS = cc.POSTIONS,
                                       REGISTER_USER_ID = cc.REGISTER_USER_ID,
                                       REGISTER_TIME = cc.REGISTER_TIME,
                                       UPDATE_USER_ID = cc.UPDATE_USER_ID,
                                       UPDATE_TIME = cc.UPDATE_TIME,
                                       STATUS = cc.STATUS,
                                       UNREGISTER_TIME = cc.UNREGISTER_TIME,
                                       UNREGISTER_REASON = cc.UNREGISTER_REASON,
                                       DRIVER_NAME = cc.DRIVER_NAME,
                                       UNREGISTER_USER_ID = cc.UNREGISTER_USER_ID,
                                       CAR_TYPE = cc.CAR_TYPE,
                                       CAR_SIZE = cc.CAR_SIZE
                                   }).ToList();
                    var car = (from o in db.PUB_CAR_OPERATE
                               join d in db.PUB_CAR on o.CAR_ID equals d.CAR_ID
                               join b in db.SysUser
                                     on d.REGISTER_USER_ID equals b.Id into RUSER
                               from bb in RUSER.DefaultIfEmpty()
                               join a in db.SysUser
                                     on d.UPDATE_USER_ID equals a.Id into UUSER
                               from aa in UUSER.DefaultIfEmpty()
                               join e in db.SysUser
                                     on d.UNREGISTER_USER_ID equals e.Id into UNUSER
                               from ee in UNUSER.DefaultIfEmpty()
                               select new PUB_CAR_OPERATEModel
                               {
                                   CAR_ID = "最新数据",
                                   RFID = d.RFID,
                                   LPR = d.LPR,
                                   DRIVER_IDCARD = d.DRIVER_IDCARD,
                                   DRIVER_PHONE = d.DRIVER_PHONE,
                                   SPECIFIED_WEIGHT = d.SPECIFIED_WEIGHT,
                                   TARE = d.TARE,
                                   TOTLE_LENGTH = d.TOTLE_LENGTH,
                                   TOTLE_WIDTH = d.TOTLE_WIDTH,
                                   LENGTH = d.LENGTH,
                                   WIDTH = d.WIDTH,
                                   HEIGHT = d.HEIGHT,
                                   POSTIONS = d.POSTIONS,
                                   REGISTER_USER_ID = bb.TrueName,
                                   REGISTER_TIME = d.REGISTER_TIME,
                                   UPDATE_USER_ID = aa.TrueName,
                                   UPDATE_TIME = d.UPDATE_TIME,
                                   STATUS = d.STATUS,
                                   UNREGISTER_TIME = d.UNREGISTER_TIME,
                                   UNREGISTER_REASON = d.UNREGISTER_REASON,
                                   DRIVER_NAME = d.DRIVER_NAME,
                                   UNREGISTER_USER_ID = ee.TrueName,
                                   CAR_TYPE = d.CAR_TYPE,
                                   CAR_SIZE = d.CAR_SIZE
                               }).Distinct().ToList();
                    var queryData = car.Union<PUB_CAR_OPERATEModel>(caroper).AsQueryable();
                    */
                    #endregion


                    IQueryable<PUB_CAR_OPERATEModel> queryData = db.Database.SqlQuery<PUB_CAR_OPERATEModel>(string.Format(@"
                                                                                                                SELECT CAR_ID,
                                                                                                                       RFID,
                                                                                                                       LPR,
                                                                                                                       DRIVER_IDCARD,
                                                                                                                       DRIVER_PHONE,
                                                                                                                       SPECIFIED_WEIGHT,
                                                                                                                       TARE,
                                                                                                                       TOTLE_LENGTH,
                                                                                                                       TOTLE_WIDTH,
                                                                                                                       LENGTH,
                                                                                                                       WIDTH,
                                                                                                                       HEIGHT,
                                                                                                                       POSTIONS,
                                                                                                                       BB.TRUENAME       AS REGISTER_USER_ID,
                                                                                                                       REGISTER_TIME,
                                                                                                                       CC.TRUENAME       AS UPDATE_USER_ID,
                                                                                                                       UPDATE_TIME,
                                                                                                                       STATUS,
                                                                                                                       UNREGISTER_TIME,
                                                                                                                       UNREGISTER_REASON,
                                                                                                                       DRIVER_NAME,
                                                                                                                       DD.TRUENAME       AS UNREGISTER_USER_ID,
                                                                                                                       CAR_TYPE,
                                                                                                                       CAR_SIZE
                                                                                                                  FROM (SELECT '最新数据' AS CAR_ID,
                                                                                                                               RFID,
                                                                                                                               LPR,
                                                                                                                               DRIVER_IDCARD,
                                                                                                                               DRIVER_PHONE,
                                                                                                                               SPECIFIED_WEIGHT,
                                                                                                                               TARE,
                                                                                                                               TOTLE_LENGTH,
                                                                                                                               TOTLE_WIDTH,
                                                                                                                               LENGTH,
                                                                                                                               WIDTH,
                                                                                                                               HEIGHT,
                                                                                                                               POSTIONS,
                                                                                                                               REGISTER_USER_ID,
                                                                                                                               REGISTER_TIME,
                                                                                                                               UPDATE_USER_ID,
                                                                                                                               UPDATE_TIME,
                                                                                                                               STATUS,
                                                                                                                               UNREGISTER_TIME,
                                                                                                                               UNREGISTER_REASON,
                                                                                                                               DRIVER_NAME,
                                                                                                                               UNREGISTER_USER_ID,
                                                                                                                               CAR_TYPE,
                                                                                                                               CAR_SIZE
                                                                                                                          FROM (SELECT DISTINCT A.*
                                                                                                                                  FROM PUB_CAR A
                                                                                                                                 RIGHT JOIN PUB_CAR_OPERATE B
                                                                                                                                    ON A.CAR_ID = B.CAR_ID
                                                                                                                                 ORDER BY A.UPDATE_TIME) AA
                                                                                                                        UNION
                                                                                                                        SELECT TO_CHAR('第' || ROW_NUMBER() OVER(PARTITION BY CAR_ID ORDER BY
                                                                                                                                            UPDATE_TIME) || '次操作') AS CAR_ID,
                                                                                                                               RFID,
                                                                                                                               LPR,
                                                                                                                               DRIVER_IDCARD,
                                                                                                                               DRIVER_PHONE,
                                                                                                                               SPECIFIED_WEIGHT,
                                                                                                                               TARE,
                                                                                                                               TOTLE_LENGTH,
                                                                                                                               TOTLE_WIDTH,
                                                                                                                               LENGTH,
                                                                                                                               WIDTH,
                                                                                                                               HEIGHT,
                                                                                                                               POSTIONS,
                                                                                                                               REGISTER_USER_ID,
                                                                                                                               REGISTER_TIME,
                                                                                                                               UPDATE_USER_ID,
                                                                                                                               UPDATE_TIME,
                                                                                                                               STATUS,
                                                                                                                               UNREGISTER_TIME,
                                                                                                                               UNREGISTER_REASON,
                                                                                                                               DRIVER_NAME,
                                                                                                                               UNREGISTER_USER_ID,
                                                                                                                               CAR_TYPE,
                                                                                                                               CAR_SIZE
                                                                                                                          FROM PUB_CAR_OPERATE) AA
                                                                                                                  LEFT JOIN SYSUSER BB
                                                                                                                    ON AA.REGISTER_USER_ID = BB.ID
                                                                                                                  LEFT JOIN SYSUSER CC
                                                                                                                    ON AA.UPDATE_USER_ID = CC.ID
                                                                                                                  LEFT JOIN SYSUSER DD
                                                                                                                    ON AA.UNREGISTER_USER_ID = DD.ID
                                                                                                                 ")).AsQueryable();

                
                    var whereLambda = PredicateBuilder.True<PUB_CAR_OPERATEModel>();

                    if (!string.IsNullOrEmpty(queryStr))
                    {
                        whereLambda = whereLambda.And<PUB_CAR_OPERATEModel>(
                                        a => a.LPR.Contains(queryStr)
                                        || a.DRIVER_PHONE.Contains(queryStr)
                                        || a.POSTIONS.Contains(queryStr));
                    }
                    queryData = queryData.Where(whereLambda.Compile()).AsQueryable();
                    pager.totalRows = queryData.Count();
                    queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
                    return queryData.ToList();
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            
        }

    }
	public class Virtual_PUB_CAR_OPERATEBLL
	{
        [Dependency]
        public IPUB_CAR_OPERATERepository m_Rep { get; set; }

		public virtual List<PUB_CAR_OPERATEModel> GetList(ref GridPager pager, string queryStr)
        {

            IQueryable<PUB_CAR_OPERATE> queryData = null;
            if (!string.IsNullOrWhiteSpace(queryStr))
            {
                queryData = m_Rep.GetList(
								a=>  a.LPR.Contains(queryStr)
								|| a.DRIVER_PHONE.Contains(queryStr)
								|| a.POSTIONS.Contains(queryStr)
								);
            }
            else
            {
                queryData = m_Rep.GetList();
            }
            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelList(ref queryData);
        }
		 
		public virtual List<PUB_CAR_OPERATEModel> GetPagerList(ref GridPager pager, Expression<Func<PUB_CAR_OPERATE, bool>> whereLambda )
        {

            IQueryable<PUB_CAR_OPERATE> queryData = m_Rep.GetList(whereLambda); 
             
            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelList(ref queryData);
        }

		public virtual List<PUB_CAR_OPERATEModel> GetList(Expression<Func<PUB_CAR_OPERATE, bool>> whereLambda )
        {

            IQueryable<PUB_CAR_OPERATE> queryData = m_Rep.GetList(whereLambda); 
       
            return CreateModelList(ref queryData);
        }

		public virtual List<PUB_CAR_OPERATEModel> GetListByParentId(ref GridPager pager, string queryStr,object parentId)
        {
			return new List<PUB_CAR_OPERATEModel>();
		}

        public virtual List<PUB_CAR_OPERATEModel> CreateModelList(ref IQueryable<PUB_CAR_OPERATE> queryData)
        {

            List<PUB_CAR_OPERATEModel> modelList = (from r in queryData
                                                    select new PUB_CAR_OPERATEModel
                                                    {
                                                        CAR_ID = r.CAR_ID,
                                                        RFID = r.RFID,
                                                        LPR = r.LPR,
                                                        DRIVER_IDCARD = r.DRIVER_IDCARD,
                                                        DRIVER_PHONE = r.DRIVER_PHONE,
                                                        SPECIFIED_WEIGHT = r.SPECIFIED_WEIGHT,
                                                        TARE = r.TARE,
                                                        TOTLE_LENGTH = r.TOTLE_LENGTH,
                                                        TOTLE_WIDTH = r.TOTLE_WIDTH,
                                                        LENGTH = r.LENGTH,
                                                        WIDTH = r.WIDTH,
                                                        HEIGHT = r.HEIGHT,
                                                        POSTIONS = r.POSTIONS,
                                                        REGISTER_USER_ID = r.REGISTER_USER_ID,
                                                        REGISTER_TIME = r.REGISTER_TIME,
                                                        UPDATE_USER_ID = r.UPDATE_USER_ID,
                                                        UPDATE_TIME = r.UPDATE_TIME,
                                                        STATUS = r.STATUS==true ? 1 : 0,
                                                        UNREGISTER_TIME = r.UNREGISTER_TIME,
                                                        UNREGISTER_REASON = r.UNREGISTER_REASON,
                                                        CAR_SIZE = r.CAR_SIZE,

                                                    }).ToList();

            return modelList;
        }

        public virtual bool Create(ref ValidationErrors errors, PUB_CAR_OPERATEModel model)
        {
            try
            {
                PUB_CAR_OPERATE entity = m_Rep.GetById(model.CAR_ID);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return false;
                }
                entity = new PUB_CAR_OPERATE();
               				entity.CAR_ID = model.CAR_ID;
				entity.RFID =string.IsNullOrEmpty(model.RFID)?"0": model.RFID;
				entity.LPR = model.LPR;
				entity.DRIVER_IDCARD = string.IsNullOrEmpty(model.DRIVER_IDCARD) ? "000000000000000000" : model.DRIVER_IDCARD;
                entity.DRIVER_PHONE = string.IsNullOrEmpty(model.DRIVER_PHONE) ? "00000000000" : model.DRIVER_PHONE;
                entity.SPECIFIED_WEIGHT = model.SPECIFIED_WEIGHT == null ? 0 : model.SPECIFIED_WEIGHT;
                entity.TARE =model.TARE==null ? 0 : model.TARE;
                entity.TOTLE_LENGTH = model.TOTLE_LENGTH== null ? 0 : model.TOTLE_LENGTH;
                entity.TOTLE_WIDTH = model.TOTLE_WIDTH==null ? 0 : model.TOTLE_WIDTH;
                entity.LENGTH = (decimal)model.LENGTH;
				entity.WIDTH = (decimal)model.WIDTH;
				entity.HEIGHT = (decimal)model.HEIGHT;
				entity.POSTIONS = model.POSTIONS;
				entity.REGISTER_USER_ID = model.REGISTER_USER_ID;
				entity.REGISTER_TIME = model.REGISTER_TIME;
				entity.UPDATE_USER_ID = model.UPDATE_USER_ID;
				entity.UPDATE_TIME = model.UPDATE_TIME==null?DateTime.Now:DateTime.Parse(model.UPDATE_TIME.ToString());
				entity.STATUS = model.STATUS==0?false:true;
				entity.UNREGISTER_TIME = model.UNREGISTER_TIME;
				entity.UNREGISTER_REASON = model.UNREGISTER_REASON;
                entity.CAR_SIZE = model.CAR_SIZE;
  

                if (m_Rep.Create(entity))
                {
                    return true;
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

		
		 public virtual bool Deletes(ref ValidationErrors errors,Expression<Func<PUB_CAR_OPERATE, bool>> whereLambda)
         {
		        try
				{
					using (DBContainer db = new DBContainer())
					{
				
							foreach (var entity in db.PUB_CAR_OPERATE.Where(whereLambda))
							{
								db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
							}

							if(db.SaveChanges()>0)
							{
								return true;
							}
							else
							{
								return false;
							}
			
					}
				}
				catch (Exception ex)
				{
					errors.Add(ex.Message);
					ExceptionHander.WriteException(ex);
					return false;
				}
        }

         public virtual bool Delete(ref ValidationErrors errors, object id)
        {
            try
            {
                if (m_Rep.Delete(id) == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

        public virtual bool Delete(ref ValidationErrors errors, object[] deleteCollection)
        {
            try
            {
                if (deleteCollection != null)
                {
                    using (TransactionScope transactionScope = new TransactionScope())
                    {
                        if (m_Rep.Delete(deleteCollection) == deleteCollection.Length)
                        {
                            transactionScope.Complete();
                            return true;
                        }
                        else
                        {
                            Transaction.Current.Rollback();
                            return false;
                        }
                    }
                }
                return false;
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

		
       

        public virtual bool Edit(ref ValidationErrors errors, PUB_CAR_OPERATEModel model)
        {
            try
            {
                PUB_CAR_OPERATE entity = m_Rep.GetById(model.CAR_ID);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return false;
                }
                              				entity.CAR_ID = model.CAR_ID;
				entity.RFID = model.RFID;
				entity.LPR = model.LPR;
				//entity.DRIVER_IDCARD = model.DRIVER_IDCARD;
				//entity.DRIVER_PHONE = model.DRIVER_PHONE;
                entity.DRIVER_IDCARD = model.DRIVER_IDCARD=="0" ? "0" : model.DRIVER_IDCARD;
                entity.DRIVER_PHONE = model.DRIVER_PHONE =="0"? "0": model.DRIVER_PHONE;
                entity.SPECIFIED_WEIGHT = model.SPECIFIED_WEIGHT;
				entity.TARE = model.TARE;
				entity.TOTLE_LENGTH = model.TOTLE_LENGTH;
				entity.TOTLE_WIDTH = model.TOTLE_WIDTH;
				entity.LENGTH = (decimal)model.LENGTH;
				entity.WIDTH = (decimal)model.WIDTH;
				entity.HEIGHT = (decimal)model.HEIGHT;
				entity.POSTIONS = model.POSTIONS;
				entity.REGISTER_USER_ID = model.REGISTER_USER_ID;
				entity.REGISTER_TIME = model.REGISTER_TIME;
				entity.UPDATE_USER_ID = model.UPDATE_USER_ID;
				entity.UPDATE_TIME =(DateTime)model.UPDATE_TIME;
				entity.STATUS = bool.Parse(model.STATUS.ToString());
				entity.UNREGISTER_TIME = model.UNREGISTER_TIME;
				entity.UNREGISTER_REASON = model.UNREGISTER_REASON;
                entity.CAR_SIZE = model.CAR_SIZE;
 


                if (m_Rep.Edit(entity))
                {
                    return true;
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return false;
                }

            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

      

        public virtual PUB_CAR_OPERATEModel GetById(object id)
        {
            if (IsExists(id))
            {
                PUB_CAR_OPERATE entity = m_Rep.GetById(id);
                PUB_CAR_OPERATEModel model = new PUB_CAR_OPERATEModel();
                              				model.CAR_ID = entity.CAR_ID;
				model.RFID = entity.RFID;
				model.LPR = entity.LPR;
				model.DRIVER_IDCARD = entity.DRIVER_IDCARD;
				model.DRIVER_PHONE = entity.DRIVER_PHONE;
				model.SPECIFIED_WEIGHT = entity.SPECIFIED_WEIGHT;
				model.TARE = entity.TARE;
				model.TOTLE_LENGTH = entity.TOTLE_LENGTH;
				model.TOTLE_WIDTH = entity.TOTLE_WIDTH;
				model.LENGTH = entity.LENGTH;
				model.WIDTH = entity.WIDTH;
				model.HEIGHT = entity.HEIGHT;
				model.POSTIONS = entity.POSTIONS;
				model.REGISTER_USER_ID = entity.REGISTER_USER_ID;
				model.REGISTER_TIME = entity.REGISTER_TIME;
				model.UPDATE_USER_ID = entity.UPDATE_USER_ID;
				model.UPDATE_TIME = entity.UPDATE_TIME;
				model.STATUS = entity.STATUS==true?1:0;
				model.UNREGISTER_TIME = entity.UNREGISTER_TIME;
				model.UNREGISTER_REASON = entity.UNREGISTER_REASON;
                model.CAR_SIZE = entity.CAR_SIZE;
 
                return model;
            }
            else
            {
                return null;
            }
        }

		public virtual PUB_CAR_OPERATEModel GetItem(Expression<Func<PUB_CAR_OPERATE, bool>> whereLambda)
        {
 
                PUB_CAR_OPERATE entity = m_Rep.GetItem(whereLambda);
                if (entity == null) return null;

                PUB_CAR_OPERATEModel model = new PUB_CAR_OPERATEModel();
                              				model.CAR_ID = entity.CAR_ID;
				model.RFID = entity.RFID;
				model.LPR = entity.LPR;
				model.DRIVER_IDCARD = entity.DRIVER_IDCARD;
				model.DRIVER_PHONE = entity.DRIVER_PHONE;
				model.SPECIFIED_WEIGHT = entity.SPECIFIED_WEIGHT;
				model.TARE = entity.TARE;
				model.TOTLE_LENGTH = entity.TOTLE_LENGTH;
				model.TOTLE_WIDTH = entity.TOTLE_WIDTH;
				model.LENGTH = entity.LENGTH;
				model.WIDTH = entity.WIDTH;
				model.HEIGHT = entity.HEIGHT;
				model.POSTIONS = entity.POSTIONS;
				model.REGISTER_USER_ID = entity.REGISTER_USER_ID;
				model.REGISTER_TIME = entity.REGISTER_TIME;
				model.UPDATE_USER_ID = entity.UPDATE_USER_ID;
				model.UPDATE_TIME = entity.UPDATE_TIME;
				model.STATUS = entity.STATUS==true?1:0;
				model.UNREGISTER_TIME = entity.UNREGISTER_TIME;
				model.UNREGISTER_REASON = entity.UNREGISTER_REASON;
                model.CAR_SIZE = entity.CAR_SIZE;
 
                return model; 
        }


        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List<PUB_CAR_OPERATEModel> list, ref ValidationErrors errors)
        {

            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {

                errors.Add("导入的数据文件不存在");
                return false;
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.LPR, "车牌号");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.DRIVER_IDCARD, "司机身份证");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.DRIVER_PHONE, "联系电话");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.SPECIFIED_WEIGHT, "额定载重");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.TARE, "皮重");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.TOTLE_LENGTH, "车辆长度(m)");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.TOTLE_WIDTH, "车辆宽度(m)");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.LENGTH, "车厢长度(m)");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.WIDTH, "车厢宽度(m)");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.HEIGHT, "车厢高度(m)");
            excelFile.AddMapping<PUB_CAR_OPERATEModel>(x => x.POSTIONS, "拉筋位置");

            //SheetName
            var excelContent = excelFile.Worksheet<PUB_CAR_OPERATEModel>(0);
            int rowIndex = 1;
            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity = new PUB_CAR_OPERATEModel();
                entity.LPR = row.LPR;
                entity.DRIVER_IDCARD = row.DRIVER_IDCARD;
                entity.DRIVER_PHONE = row.DRIVER_PHONE;
                entity.SPECIFIED_WEIGHT = row.SPECIFIED_WEIGHT;
                entity.TARE = row.TARE;
                entity.TOTLE_LENGTH = row.TOTLE_LENGTH;
                entity.TOTLE_WIDTH = row.TOTLE_WIDTH;
                entity.LENGTH = row.LENGTH;
                entity.WIDTH = row.WIDTH;
                entity.HEIGHT = row.HEIGHT;
                entity.POSTIONS = Regex.Replace(String.Join(",", Regex.Replace(row.POSTIONS, @"([\u4e00-\u9fa5])", "-").Split('-').Where(a => !string.IsNullOrEmpty(a))), @"([\\s|\u3000|\uff0c]+)", ",");


                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                        "第 {0} 列发现错误：{1}{2}",
                        rowIndex,
                        errorMessage,
                        "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable<PUB_CAR_OPERATEModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        PUB_CAR_OPERATE entity = new PUB_CAR_OPERATE();
                       	entity.CAR_ID = ResultHelper.NewId;
                        entity.RFID = string.IsNullOrEmpty(model.RFID) ? "0" : model.RFID;
						entity.LPR = model.LPR;
						entity.DRIVER_IDCARD = model.DRIVER_IDCARD;
						entity.DRIVER_PHONE = model.DRIVER_PHONE;
						entity.SPECIFIED_WEIGHT = model.SPECIFIED_WEIGHT;
						entity.TARE = model.TARE;
						entity.TOTLE_LENGTH = model.TOTLE_LENGTH;
						entity.TOTLE_WIDTH = model.TOTLE_WIDTH;
						entity.LENGTH = (decimal)model.LENGTH;
						entity.WIDTH = (decimal)model.WIDTH;
						entity.HEIGHT = (decimal)model.HEIGHT;
						entity.POSTIONS = model.POSTIONS;
						entity.REGISTER_USER_ID = model.REGISTER_USER_ID;
						entity.REGISTER_TIME = DateTime.Now;
						entity.UPDATE_USER_ID = model.UPDATE_USER_ID;
						entity.UPDATE_TIME =(DateTime) model.UPDATE_TIME;
						entity.STATUS = bool.Parse(model.STATUS.ToString());
						entity.UNREGISTER_TIME = model.UNREGISTER_TIME;
						entity.UNREGISTER_REASON = model.UNREGISTER_REASON;
                        entity.CAR_SIZE = model.CAR_SIZE;
 
                        db.PUB_CAR_OPERATE.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch
            {
                throw;
            }
        }


        public virtual bool IsExists(object id)
        {
            return m_Rep.IsExist(id);
        }
		  public void Dispose()
        { 
            
        }

	}
}
